# 二分法实现
# 找到返回下标，未找到返回-1
def binary_search(search_list, start, end, target_num):
    if start > end:
        print('未找到目标值')
        return -1
    mid = (start + end) // 2
    if search_list[mid] == target_num:
        print('找到目标值')
        return mid
    elif search_list[mid] < target_num:
        start = mid + 1
    else:
        end = mid - 1
    return binary_search(search_list, start, end, target_num)


# 列表生产式 生成0-99列表
search_list = [i for i in range(100)]
# 需要查找的目标值
target_num = 99
res = binary_search(search_list, 0, len(search_list) - 1, target_num)
print("目标值下标为 %s" % res)
